<?php

namespace App\Models;

use App\Enums\GoodsTypeStatusEnum;
use App\Traits\ModelEventTrait;
use Illuminate\Database\Eloquent\SoftDeletes;

class HelpCategory extends BaseModel
{
    use ModelEventTrait;
    use SoftDeletes;

    const KEY = 'id';
    const TABLE = 'sp_help_category';

    protected $table = self::TABLE;
    protected $primaryKey = self::KEY;
    protected $connection = 'mysql';

    // public $timestamps = false;
    const CREATED_AT = 'create_time';
    const UPDATED_AT = 'update_time';
    const DELETED_AT = 'delete_time';

    protected $guarded = [];


    protected $hidden = [
        self::DELETED_AT,
    ];

    protected $casts = [
        'create_time' => 'datetime:Y-m-d H:i:s',
        'update_time' => 'datetime:Y-m-d H:i:s',
    ];

    protected $appends = ['img_url'];


    public function getImgUrlAttribute()
    {
        if($this->image){
            return config('alipay.oss.imgHost').$this->image;
        }else{
            return '';
        }
    }


    public static function findById($id)
    {
        return self::query()->find($id);
    }

    public function getAll()
    {
        return (new static())->select(
            'id',
            'image',
            'name',
            'type',
            'sort',
            'create_time',
        )->get();
    }
}
